package utils;

import java.math.BigDecimal;
import java.util.Random;

public class CreatDataUtils {
    public static String BLANK = " ";
    public static String EMPTY = "";
    public static String LF = "\r\n";

    public static void main(String[] args) {
        // 随机生成排序用的测试数据
        // 生成普通版本，数值范围在int取值范围内，-2147483648 ~ 2147483647
        // n-代表普通版本，1k - 1千个数据，
        create(1000, "n_1k");
        create(10_000, "n_1w");
        create(100_000, "n_10w");
        create(1_000_000, "n_100w");
        create(5_000_000, "n_500w");

        // 生成大数版本,数值的范围在[（-10）^100,10^100]
        // B-代表大数版本，1w - 1万个数据，
        createBigDta(1000, "B_1k");
        createBigDta(10_000, "B_1w");
        createBigDta(100_000, "B_10w");
    }

    private static void createBigDta(int num, String fileName) {
        String content = EMPTY;
        for (int i = 0; i < num; i++) {
            Random ran = new Random();
            int[] Gene = new int[100];
            for (int j = 0; j < 100; j++) {
                Gene[j] = ran.nextInt(2);
            }
            double result = transformBin2Int(Gene);
            if (ran.nextInt(2) == 0) {
                result = -result;
            }
            content += new BigDecimal(result).toString();
            FileUtils.writeTxt(content, fileName);
            content = LF;
        }
    }

    public static double transformBin2Int(int[] Gene) {
        double Result = 0;
        double tmp = 0;
        for (int i = 0; i < Gene.length; i++) {
            tmp = Result + Gene[i] * Math.pow(2, (Gene.length - 1 - i));
            Result = tmp;
        }
        return Result;
    }

    private static void create(int num, String fileName) {
        // nextInt()会生成所有有效的整数（包含正数，负数，0）
        String content = EMPTY;
        Random ran = new Random();
        for (int i = 1; i <= num; i++) {
            content += ran.nextInt() + BLANK;
            if (i % 10 == 0) {
                content = content.substring(0, content.length() - 1);
                FileUtils.writeTxt(content, fileName);
                System.out.println(content);
                content = LF;
            }
        }
    }
}
